import './index.less';
import './tools/Date';
import './icon/iconfont.css';
import App from './App';
let app = new App();

Message.success = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "success",
            message: value
        });
    }

    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "success",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
Message.warning = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "warning",
            message: value
        });
    }
    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "warning",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
Message.info = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "info",
            message: value
        });
    }
    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "info",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
Message.error = function (value) {
    if (typeof value == 'string') {
        app.Message({
            type: "error",
            message: value
        });
    }
    else if (typeof value == 'object' && !(value instanceof Array)) {
        value['type'] && delete value['type']
        app.Message({
            type: "error",
            ...value
        });
    } else {
        throw new Error("reference error")
    }
}
export function Message(options) {
    app.Message(options);
}

export let Loading = {
    service(options) {
        return app.Loading(options)
    }
}

export function Upload(options) {
    app.Upload(options)
}

/* module.exports = {
    Upload: Upload,
    Loading: Loading,
    Message: Message,
} */

export default {
    Upload: Upload,
    Loading: Loading,
    Message: Message,
    install(Vue) {
        // vue2
        if (typeof Vue == 'function') {
            Vue.prototype.$msg = Message;
            Vue.prototype.$loading = Loading;
            Vue.prototype.$upload = Upload;
        }
        // vue3
        if (typeof Vue == 'object') {
            /*  
                使用
                const { proxy } = getCurrentInstance();
                const { $msg, $loading, $upload } = proxy;
            */
            Vue.config.globalProperties.$msg = Message;
            Vue.config.globalProperties.$loading = Loading;
            Vue.config.globalProperties.$upload = Upload;
        }
    }
}


